﻿using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using Unity.MLAgents;
using Unity.MLAgents.Sensors;
using Unity.MLAgents.Actuators;

public class FlightAgentBuffer : FlightAgent
{    
    private BufferSensorComponent bufferSensorComponent;
    public override void Initialize()
    {
        base.Initialize();
        bufferSensorComponent = GetComponent<BufferSensorComponent>();
    }
    public override void CollectObservations(VectorSensor sensor)
    {
        // Target position
        sensor.AddObservation(plygrndCtrler.target.localPosition);
        
        // Agent status
        sensor.AddObservation(airplane.rBody.velocity);
        sensor.AddObservation(airplane.rBody.angularVelocity);
        sensor.AddObservation(airplane.transform.localRotation);
        sensor.AddObservation(airplane.transform.localPosition);

        // BadSphere position
        int obsNum = 0;
        foreach(BadSphere badSphere in plygrndCtrler.badSpheres)
        {
            if(obsNum > bufferSensorComponent.MaxNumObservables)
                break;
            obsNum++;
            Vector3 pos = badSphere.transform.localPosition;
            float[] obs = {pos.x, pos.y, pos.z, badSphere.transform.localScale.x};
            bufferSensorComponent.AppendObservation(obs);
        }
        
    }
}